| Conditions | 1 |
| Paths | 1 |
| Total Lines | 175 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | |||
| 66 | const sandcageWithWrongKey = new Sandcage({apiKey: WRONG_KEY}); |
||
| 67 | |||
| 68 | before('init nock', () => { |
||
| 69 | specHelper.initNock(); |
||
| 70 | }); |
||
| 71 | |||
| 72 | describe('getInfo', () => { |
||
| 73 | |||
| 74 | let response; |
||
| 75 | |||
| 76 | before('call getInfo', () => { |
||
| 77 | return sandcage |
||
| 78 | .getInfo({'request_id': REQUEST_ID}) |
||
| 79 | .then((result) => { |
||
| 80 | response = result; |
||
| 81 | }); |
||
| 82 | }); |
||
| 83 | |||
| 84 | it('should contain status', () => { |
||
| 85 | return expect(response.status).to.exist; |
||
| 86 | }); |
||
| 87 | |||
| 88 | it('status should be "success"', () => { |
||
| 89 | expect(response.status).to.be.equal('success'); |
||
| 90 | }); |
||
| 91 | |||
| 92 | it('files should be an array', () => { |
||
| 93 | expect(response.files).to.be.an('array'); |
||
| 94 | }); |
||
| 95 | }); |
||
| 96 | |||
| 97 | describe('getInfo with wrong key', () => { |
||
| 98 | |||
| 99 | let response; |
||
| 100 | |||
| 101 | before('call getInfo', () => { |
||
| 102 | return sandcageWithWrongKey |
||
| 103 | .getInfo({'request_id': REQUEST_ID}) |
||
| 104 | .catch((err) => { |
||
| 105 | response = err; |
||
| 106 | }); |
||
| 107 | }); |
||
| 108 | |||
| 109 | it('should catch error', () => { |
||
| 110 | return expect(response).to.exist; |
||
| 111 | }); |
||
| 112 | }); |
||
| 113 | |||
| 114 | describe('listFiles', () => { |
||
| 115 | |||
| 116 | let response; |
||
| 117 | |||
| 118 | before('call listFiles', () => { |
||
| 119 | return sandcage |
||
| 120 | .listFiles({directory: 'img/'}) |
||
| 121 | .then((result) => { |
||
| 122 | response = result; |
||
| 123 | }); |
||
| 124 | }); |
||
| 125 | |||
| 126 | it('should contain status', () => { |
||
| 127 | return expect(response.status).to.exist; |
||
| 128 | }); |
||
| 129 | |||
| 130 | it('status should be "success"', () => { |
||
| 131 | expect(response.status).to.be.equal('success'); |
||
| 132 | }); |
||
| 133 | |||
| 134 | it('files should be an array', () => { |
||
| 135 | expect(response.files).to.be.an('array'); |
||
| 136 | }); |
||
| 137 | }); |
||
| 138 | |||
| 139 | describe('listFiles with wrong key', () => { |
||
| 140 | |||
| 141 | let response; |
||
| 142 | |||
| 143 | before('call listFiles', () => { |
||
| 144 | return sandcageWithWrongKey |
||
| 145 | .listFiles({directory: 'img/'}) |
||
| 146 | .catch((err) => { |
||
| 147 | response = err; |
||
| 148 | }); |
||
| 149 | }); |
||
| 150 | |||
| 151 | it('should catch error', () => { |
||
| 152 | return expect(response).to.exist; |
||
| 153 | }); |
||
| 154 | }); |
||
| 155 | |||
| 156 | describe('scheduleTasks', () => { |
||
| 157 | |||
| 158 | let response; |
||
| 159 | |||
| 160 | before('call scheduleTasks', () => { |
||
| 161 | return sandcage |
||
| 162 | .scheduleFiles({jobs: JOBS}, CALLBACK_URL) |
||
| 163 | .then((result) => { |
||
| 164 | response = result; |
||
| 165 | }); |
||
| 166 | }); |
||
| 167 | |||
| 168 | it('should contain status', () => { |
||
| 169 | return expect(response.status).to.exist; |
||
| 170 | }); |
||
| 171 | |||
| 172 | it('status should be "success"', () => { |
||
| 173 | expect(response.status).to.be.equal('success'); |
||
| 174 | }); |
||
| 175 | |||
| 176 | it('tasks should be an array', () => { |
||
| 177 | expect(response.tasks).to.be.an('array'); |
||
| 178 | }); |
||
| 179 | }); |
||
| 180 | |||
| 181 | describe('scheduleTasks with wrong key', () => { |
||
| 182 | |||
| 183 | let response; |
||
| 184 | |||
| 185 | before('call scheduleTasks', () => { |
||
| 186 | return sandcageWithWrongKey |
||
| 187 | .scheduleFiles({jobs: JOBS}, CALLBACK_URL) |
||
| 188 | .catch((err) => { |
||
| 189 | response = err; |
||
| 190 | }); |
||
| 191 | }); |
||
| 192 | |||
| 193 | it('should catch error', () => { |
||
| 194 | return expect(response).to.exist; |
||
| 195 | }); |
||
| 196 | }); |
||
| 197 | |||
| 198 | describe('destroyFiles', () => { |
||
| 199 | |||
| 200 | let response; |
||
| 201 | |||
| 202 | before('call destroyFiles', () => { |
||
| 203 | return sandcage |
||
| 204 | .destroyFiles({files: FILES}, CALLBACK_URL) |
||
| 205 | .then((result) => { |
||
| 206 | response = result; |
||
| 207 | }); |
||
| 208 | }); |
||
| 209 | |||
| 210 | it('should contain status', () => { |
||
| 211 | return expect(response.status).to.exist; |
||
| 212 | }); |
||
| 213 | |||
| 214 | it('status should be "success"', () => { |
||
| 215 | expect(response.status).to.be.equal('success'); |
||
| 216 | }); |
||
| 217 | |||
| 218 | }); |
||
| 219 | |||
| 220 | describe('destroyFiles with wrong key', () => { |
||
| 221 | |||
| 222 | let response; |
||
| 223 | |||
| 224 | before('call destroyFiles', () => { |
||
| 225 | return sandcageWithWrongKey |
||
| 226 | .destroyFiles({files: FILES}, CALLBACK_URL) |
||
| 227 | .catch((err) => { |
||
| 228 | response = err; |
||
| 229 | }); |
||
| 230 | }); |
||
| 231 | |||
| 232 | it('should catch error', () => { |
||
| 233 | return expect(response).to.exist; |
||
| 234 | }); |
||
| 235 | }); |
||
| 236 | |||
| 237 | }); |
||
| 238 | |||
| 239 |